//
//  SqliteManager+HandleFarmer.m
//  HandleFarmer
//
//  Created by Cheney Lau on 7/31/14.
//  Copyright (c) 2014 Handou. All rights reserved.
//

#import "SqliteManager+Base.h"
#import "FMDB.h"

@implementation SqliteManager (Base)

#pragma mark 获取周
- (NSString *)getWeek:(int)wk
{
    switch (wk) {
        case 0:
            return @"日";
            break;
        case 1:
            return @"一";
            break;
        case 2:
            return @"二";
            break;
        case 3:
            return @"三";
            break;
        case 4:
            return @"四";
            break;
        case 5:
            return @"五";
            break;
        case 6:
            return @"六";
            break;
            
        default:
            break;
    }
    return nil;
}

#pragma mark 获取一行某个字段的数据float型或string类型：一个参数
- (float)floatResultWithSql:(NSString *)sql andOneParam:(NSString *)param andFieldName:(NSString *)fieldName
{
    FMResultSet *rs = [self executeQueryWithSql:[NSString stringWithFormat:sql,param]];
    float f = 0;
    if(rs != nil)
    {
        while ([rs next]) {
            f = [rs doubleForColumn:fieldName];
        }
        [rs close];
    }
    return f;
}

- (NSString *)stringResultWithSql:(NSString *)sql andOneParam:(NSString *)param andFieldName:(NSString *)fieldName
{
    FMResultSet *rs = [self executeQueryWithSql:[NSString stringWithFormat:sql,param]];
    NSString *s = @"";
    if(rs != nil)
    {
        while ([rs next]) {
            s = [rs stringForColumn:fieldName];
        }
        [rs close];
    }
    return s;
}

#pragma mark 获取一行某个字段的数据float型或string类型：两个参数
- (float)floatResultWithSql:(NSString *)sql andOneParam:(NSString *)paramOne andTwoParam:(NSString *)paramTwo andFieldName:(NSString *)fieldName
{
    NSString *rsql = [NSString stringWithFormat:sql,paramOne,paramTwo];
    FMResultSet *rs = [self executeQueryWithSql:rsql];
    float f = 0;
    if(rs != nil)
    {
        while ([rs next]) {
            f = [rs intForColumn:fieldName];
        }
        [rs close];
    }
    return f;
}

- (NSString *)stringResultWithSql:(NSString *)sql andOneParam:(NSString *)paramOne andTwoParam:(NSString *)paramTwo andFieldName:(NSString *)fieldName
{
    FMResultSet *rs = [self executeQueryWithSql:[NSString stringWithFormat:sql,paramOne,paramTwo]];
    NSString *s = @"";
    if(rs != nil)
    {
        while ([rs next]) {
            s = [rs stringForColumn:fieldName];
        }
        [rs close];
    }
    return s;
}



@end
